<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>addressbook-联系人</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/mui.indexedlist.css" rel="stylesheet" />
		<link href="css/icons-extra.css" rel="stylesheet" type="text/css" />
		<style>
			html,
			body {
				height: 100%;
				overflow: hidden;
			}
			.mui-bar {
				-webkit-box-shadow: none;
				box-shadow: none;
			}
			div#search{padding:10px;}
			span{margin:10px;}
			#listArea {
				height: 15px;
				line-height: 15px;
				font-size: 14px; !important;
			}
			/*#emotion {
				width: 10px;
				height: 10px;
			}*/
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">联系人</h1>
		</header>
		<div class="mui-content">
			<div id='list' class="mui-indexed-list">
				<div class="mui-indexed-list-search mui-input-row mui-search" id="search">
					<input type="search" id="search" class="mui-input-clear mui-indexed-list-search-input" placeholder="搜索联系人">
				</div>
				<div class="mui-indexed-list-bar">
					<a>A</a>
					<a>B</a>
					<a>C</a>
					<a>D</a>
					<a>E</a>
					<a>F</a>
					<a>G</a>
					<a>H</a>
					<a>I</a>
					<a>J</a>
					<a>K</a>
					<a>L</a>
					<a>M</a>
					<a>N</a>
					<a>O</a>
					<a>P</a>
					<a>Q</a>
					<a>R</a>
					<a>S</a>
					<a>T</a>
					<a>U</a>
					<a>V</a>
					<a>W</a>
					<a>X</a>
					<a>Y</a>
					<a>Z</a>
				</div>
				<div class="mui-indexed-list-alert"></div>
				<div class="mui-indexed-list-inner flex-container">
					<div class="mui-indexed-list-empty-alert">没有数据</div>
					<ul class="mui-table-view" id="headArea">
						<a id="friend" class="mui-text-justify"><img class="mui-btn-link" width="40px" height="40px" src="" />认识的人</a>
						<a id="stranger" class="mui-text-justify"><img class="mui-btn-link" width="40px" height="40px" src="" />陌生人</a>
					</ul>
					<ul class="mui-table-view" id="listArea" style="height: 10px;line-height: 10px;">
						<li data-group="A" class="mui-table-view-divider mui-indexed-list-group">A</li>
					</ul>
				</div>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/mui.indexedlist.js"></script>
		<script src="js/common.js"></script>
		<script src="js/app.js"></script>
		<script src="js/pinyin.js"></script>
		<script type="text/javascript" charset="utf-8">
			mui.init();
			mui.ready(function() {
				var header = document.querySelector('header.mui-bar');
				var list = document.getElementById('list');
				//calc hieght
				list.style.height = (document.body.offsetHeight - header.offsetHeight) + 'px';
				//create
				window.indexedList = new mui.IndexedList(list);
			});
			mui.plusReady(function() {
				//var li = document.createElement("li");
				// 扩展API加载完毕，现在可以正常调用扩展API
				plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function(addressbook) {
					addressbook.find(["displayName", "phoneNumbers"], function(contacts) {
						for(var i = 0, len = contacts.length; i < len; i++) {
							var li = document.createElement("li");
							li.setAttribute('data-value', ConvertPYJC(contacts[i].displayName));
							li.setAttribute('data-tags', ConvertPinyin(contacts[i].displayName));
							li.setAttribute('data-title-type', 'native');
							li.setAttribute('id', 'imchat'+i);
							//li.className = 'imchat'+i;
							li.classList.add('mui-table-view-cell');
							li.classList.add('mui-indexed-list-item');
							if (contacts[i].photos == null) {
								li.innerHTML = '<img id="emoticon" class="mui-btn-link" width="30px" height="30px" src="" /><span id="contact">' + contacts[i].displayName + '</span>';
							} else {
								li.innerHTML = '<img id="emoticon" class="mui-btn-link" width="30px" height="30px" src="'+ contacts[i].photos +'" /><span id="contact">' + contacts[i].displayName + '（手机：' + (contacts[i].phoneNumbers.length == 0 ? '""' : contacts[i].phoneNumbers[0].value) + '）</span>';
							}
							document.getElementById("listArea").appendChild(li);
							//TODO: 根据首字母增加data-group分类
							//<li data-group="Z" class="mui-table-view-divider mui-indexed-list-group">Z</li>
						
							//聊天对话框
							var imchat = document.querySelector('#imchat'+i);
							imchat.addEventListener('tap', function(event) {
								//alert(this.id);
								clicked("im-chat.html", true, {
									"mid": this.id   //TODO: 传入id获取好友头像和聊天历史记录
								});
							});
						}

					}, function() {
						mui.toast("获取电话簿失败 ");
					}, {
						multiple: true
					});
					
				}, function(e) {
					mui.toast("获取电话簿失败 " + e.message);
				});
				
			});
		</script>
	</body>

</html>